<%@ page language="java" pageEncoding="UTF-8" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>业务系统登记</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <%@include file="../../common/Include_input_head.jsp" %>
    <script type="text/javascript" src="${basePath }/component/datepicker/WdatePicker.js"></script>
    <script type="text/javascript">
        detailPageStyle();
        function doSave() {
            if (isValidateForm()) {
                super_doSave();
            }
        }
        function input() {
            window.location.href = '<%=basePath%>id/idMenu-input.action?tsysMenu.upmenuid=000&tsysMenu.belongtoapp=' + $("#appid").val();
        }
        window.onload = function () {
            //新增修改界面不能添加子菜单
            if (!window.parent.document.getElementById('menuContentFrame')) {
                $("#ysInsertButton").hide();
            }
            if (!$(":radio[name='accessAppReg.syncDirection'][value='2']").is(":checked")) {
                $("#ysInsertButton").hide();
            }
        }
        //立即抽取
        function ljcq() {
            var url = document.getElementById("appurl").value;
            if (url == "") {
                alert("错误！业务系统地址为空！无法进行数据抽取！");
            } else {
                url += "/ServerControlServlet?type=uploadResourcesToServer";
                top.Dialog.confirm("确认要进行数据抽取操作吗？", function () {
                    /*   showProgressBar('正在向业务系统发送数据抽取指令...');
                     url="http://localhost:8080/identity/index.action";
                     sysAlert(url);
                     $.ajax({
                     url: url,
                     cache: false,
                     dataType:'html',
                     timeout:5,
                     type: "GET",
                     success: function(html){
                     alert(url+"的返回值是"+html);
                     closeProgress();
                     },
                     error:function(){
                     alert("网络错误！请检查【" +url +"】是否正确！");
                     closeProgress();
                     }, statusCode: {404: function() {
                     alert('请求地址不存在！');
                     }
                     }
                     });*/
                    showProgressBar('正在向业务系统发送数据抽取指令...');
                    $.ajax({
                        type: "GET",
                        url: url,
                        success: function (msg) {
                            closeProgress();
                            alert("数据抽取完成！刷新当前界面可以看到新的数据。" + msg);

                        }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                            closeProgress();
                            this; // 调用本次AJAX请求时传递的options参数
                            alert("网络错误！请检查【" + url + "】是否正确！");
                        }
                    });

                });


            }
        }
    </script>
    <script type="text/javascript">
        $(document).ready(function () {

            var xtlx = document.getElementById("xtlx").value;

            //点击新增默认为livebos系统
            if (xtlx == null || xtlx == '') {
                xtlx = 1;
            }
            if (xtlx == 0) {
//                $("#drivertr").hide();
//                $("#urltr").hide();
//                $("#nametr").hide();
//                $("#pwdtr").hide();
                $("#tblxtr").hide();
                $("#dbtr").hide();
            } else if (xtlx == 1) {
//                $("#drivertr").show();
//                $("#urltr").show();
//                $("#nametr").show();
//                $("#pwdtr").show();
                $("#tblxtr").show();
                $("#dbtr").show();
            }
        });
        var driverT = '';
        var urlT = '';
        var nameT = '';
        var passwordT = '';
        function dataCheck() {
//            var driver = document.getElementById("driver").value;
//            var url = document.getElementById("url").value;
//            var name = document.getElementById("name").value;
//            var password = document.getElementById("password").value;
//            if (driver != '' || url != '' || name != '' || password != '') {
//                driverT = driver;
//                urlT = url;
//                nameT = name;
//                passwordT = password;
//            }
            var xtlx = $("input[name='accessAppReg.xtlx']:checked").val()
            if (xtlx == 1) {
//                document.getElementById("driver").value = driverT;
//                document.getElementById("url").value = urlT;
//                document.getElementById("name").value = nameT;
//                document.getElementById("password").value = passwordT;
//                $("#drivertr").show();
//                $("#urltr").show();
//                $("#nametr").show();
//                $("#pwdtr").show();
                $("#tblxtr").show();
                $("#dbtr").show();
            } else {
//                document.getElementById("driver").value = '';
//                document.getElementById("url").value = '';
//                document.getElementById("name").value = '';
//                document.getElementById("password").value = '';
//                $("#drivertr").hide();
//                $("#urltr").hide();
//                $("#nametr").hide();
//                $("#pwdtr").hide();
                $("#tblxtr").hide();
                $("#dbtr").hide();

            }
        }
    </script>
    <style type="text/css">
        .longwith {
            width: 550px;;
        }
    </style>
</head>

<body style="text-align:center;">

<s:form name="theform" method="post" theme="simple">
    <s:hidden name="accessAppReg.appid" id="appid"/>

    <div class="box1" panelWidth="100%">
        <fieldset>
            <legend>业务系统信息</legend>
            <table class="tableStyle" transMode="true" footer="normal">
                <s:if test="accessAppReg.appid !=null">
                    <tr>
                        <td align="right" width="25%" nowrap="nowrap">接入号：</td>
                        <td width="75%" align="left"><s:property value="accessAppReg.appid"/></td>
                    </tr>
                </s:if>
                <tr>
                    <td align="right" width="25%" nowrap="nowrap">业务系统名字：</td>
                    <td width="75%" align="left">
                        <s:textfield name="accessAppReg.appname" id="appname" cssStyle="width: 500px;"/>
                        <label style="color:red">*</label></td>
                </tr>
                <tr>
                    <td align="right">业务系统地址：</td>
                    <td align="left">
                        <s:textfield name="accessAppReg.appurl" id="appurl" cssStyle="width: 500px;"/>
                        <label style="color:red">*</label></td>
                </tr>
                <tr>
                    <td align="right">备注：</td>
                    <td align="left">
                        <s:textarea name="accessAppReg.memo" id="memo" cssStyle="width: 500px;" maxlength="50"/>
                    </td>
                </tr>

                <tr>
                    <td align="right">受管类型：</td>
                    <td align="left">
                        <span class="float_left">
                        <s:radio name="accessAppReg.syncDirection" list="#{1:'自管',2:'托管'}"
                                 value="%{accessAppReg==null?'1':accessAppReg.syncDirection}" listKey="key"
                                 listValue="value"/>
                        </span>
                        <span class="img_light" style="height:22px;"
                              title="自管是指：客户端业务系统自行管理资源和权限，权限中心只能查看；<br/>托管是指：允许权限中心管理资源和权限，客户端每次从服务端取资源和验证权限。"></span>
                    </td>
                </tr>

                <tr>
                    <td align="right">是否启用：</td>
                    <td align="left">
                        <s:radio name="accessAppReg.state" list="getSysCode('BOOLEAN')"
                                 value="%{accessAppReg==null?'1':accessAppReg.state}"
                                 listKey="id" listValue="caption"/>
                        <label style="color:red">*</label></td>
                </tr>
                <tr>
                    <td align="right">排序值：</td>
                    <td align="left" colspan="3"><s:textfield id="ordernum" name="accessAppReg.ordernum" maxlength="3"
                                                              size="4"
                                                              onkeypress="NumberText(event)" cssStyle="width: 200px"/>
                        <label style="color:red">*</label>
                        <font color="#999999">说明：同一层次中数值大的往前排</font></td>
                </tr>
                <tr>
                    <td align="right">是否为livebos系统：</td>
                    <td align="left">
                        <s:radio name="accessAppReg.xtlx" id="accessAppReg.xtlx" list="getSysCode('BOOLEAN')"
                                 value="%{accessAppReg==null?'1':accessAppReg.xtlx}"
                                 listKey="id" listValue="caption" onclick="dataCheck()"/>
                        <label style="color:red">*</label></td>
                    <s:hidden id="xtlx" name="xtlx" value="%{accessAppReg.xtlx}"/>
                </tr>
                <tr id="tblxtr">
                    <td align="right">同步类型：</td>
                    <td align="left">
                        <%--<s:radio name="accessAppReg.tblx" list="getSysCode('BOOLEAN')"--%>
                                 <%--value="%{accessAppReg==null?'1':accessAppReg.tblx}"--%>
                                 <%--listKey="id" listValue="caption"/>--%>

                            <input type="radio" name="accessAppReg.tblx" id = "ctms" value="0" <s:if test="accessAppReg.tblx==0">checked="checked"  </s:if> >lbfun模式
                            <input type="radio" name="accessAppReg.tblx" id = "qxsms" value="1" <s:if test="accessAppReg.tblx==1">checked="checked"  </s:if>>lbauth模式
                        <label style="color:red">*</label></td>
                </tr>
                <%--
                <tr id="drivertr">
                    <td align="right">数据库驱动：</td>
                    <td align="left">
                        <s:textfield id="driver" name="accessAppReg.driver" cssStyle="width: 500px"/> <label
                            style="color:red">*</label></td>
                </tr>
                <tr id="urltr">
                    <td align="right">数据库地址：</td>
                    <td align="left">
                        <s:textfield id="url" name="accessAppReg.url" cssStyle="width: 500px"/> <label
                            style="color:red">*</label></td>
                </tr>
                <tr id="nametr">
                    <td align="right">数据库用户名：</td>
                    <td align="left">
                        <s:textfield id="name" name="accessAppReg.name" cssStyle="width: 500px"/> <label
                            style="color:red">*</label></td>
                </tr>
                <tr id="pwdtr">
                    <td align="right">数据库密码：</td>
                    <td align="left">
                        <s:textfield id="password" name="accessAppReg.password" cssStyle="width: 500px"/> <label
                            style="color:red">*</label></td>
                </tr>
                --%>

                <tr id="dbtr">
                    <td align="right">数据源：</td>
                    <td align="left">
                        <s:select id="groupid" name="accessAppReg.db" list="Dbs" listKey="id" listValue="caption"/> <label style="color:red">*</label>
                    </td>
                </tr>

            </table>
        </fieldset>

        <div class="padding_top10">
            <table class="tableStyle" transMode="true">
                <tr>
                    <td colspan="4">
                        <input type="button" id="ysSaveButton" value=" 保 存 " onclick="doSave()"/>
                        <input type="button" value=" 关 闭 " onclick="parent.closeEntityWindow()"/>
                        <input type="button" id="ysInsertButton" value=" 添加资源 " onclick="input()" title="在此节点下添加子资源"/>
                        <s:if test="accessAppReg.syncDirection==2">
                            <input type="button" id="ysInsertButton" value=" 立即抽取 " onclick="ljcq()"
                                   title="立即抽取此业务系统的全部资源和角色授权数据到服务端"/>
                        </s:if>
                        <s:if test="actionErrors.size()>0 || actionMessages.size()>0 || fieldErrors.size()>0">
						<span id="SystemErrorMessage" style="top: 20px">
							<s:actionerror cssStyle="color:red"/>
							<s:actionmessage cssStyle="color:blue"/>
							<s:fielderror/>
						</span>
                        </s:if>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</s:form>
</body>
</html>
